package cn.edu.huas.shopping.pojo;

public class CartItem {
    private Product product;
    private Integer qty;

    //java中规定重写了equals方法就一定要重写hashcode方法
    @Override
    public int hashCode() {
        return this.product.getId();
    }
    @Override
    public boolean equals(Object obj) {
        if(obj==null)return false;
        if (this==obj)return true;
        if (obj instanceof CartItem){
            CartItem other= (CartItem) obj;
            return this.product.getId()==other.product.getId();
        }
        return false;
    }

    public CartItem(Product product, Integer qty) {
        this.product = product;
        this.qty = qty;
    }
    public CartItem() {
    }




    public Product getProduct() {
        return product;
    }
    public void setProduct(Product product) {
        this.product = product;
    }

    public Integer getQty() {
        return qty;
    }

    public void setQty(Integer qty) {
        this.qty = qty;
    }

    @Override
    public String toString() {
        return "CartItem{" +
                "product=" + product +
                ", qty=" + qty +
                '}';
    }
}
